Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

Previous Next
Subject: VBA code works with Inbox, but not other folders
Feedback Type: Problem
Product Area: Notes Single Login
Technical Area: Customization
Platform: Windows
Release: 8.5.2
Reproducible: Always

I have an excel macro that is saving all attachments to a specific folder on my hard drive. Right now it is looking at all the files in my inbox. I want to change this to a folder i have setup as "test". I replaced the word "$Inbox" with "test" but it didn't work. Gave me the error "Run-time error '91' Object variable or With block variable not set" and highlighted the line containing Set noDocument = noView.GetFirstDocument


Here is my code:

Option Explicit

Const stPath As String = "c:\Attachments\"

Const EMBED_ATTACHMENT As Long = 1454

Const RICHTEXT As Long = 1

Sub Save_Remove_Attachments()
Dim noSession As Object
Dim noDatabase As Object
Dim noView As Object
Dim noDocument As Object
Dim noNextDocument As Object

'Embedded objects are of the datatype Variant.
Dim vaItem As Variant
Dim vaAttachment As Variant

'Instantiate the Notes session.
Set noSession = CreateObject("Notes.NotesSession")

'Instantiate the actual Notes database.
'(Here is the personal e-mail database used and since it's a
'local database no reference is made to any server.)
Set noDatabase = noSession.GetDatabase("", "")
If Not noDatabase.IsOpen = True Then noDatabase.Openmail 'open the mail part of it


'Folders are views in Lotus Notes and in this example the Inbox is used.
Set noView = noDatabase.GetView("($test)")

'Get the first document in the defined view.
Set noDocument = noView.GetFirstDocument

'Iterate through all the e-mails in the view Inbox.
Do Until noDocument Is Nothing

'Although the following approach is not necessary for this
'kind of operations it may be a good approach to use in general.
Set noNextDocument = noView.GetNextDocument(noDocument)

'Check if the document has an attachment or not.
If noDocument.HasEmbedded Then
Set vaItem = noDocument.GetFirstItem("Body")
If vaItem.Type = RICHTEXT Then
For Each vaAttachment In vaItem.EmbeddedObjects
If vaAttachment.Type = EMBED_ATTACHMENT Then
'Save the attached file into the new folder and remove it from the e-mail.
With vaAttachment
.ExtractFile stPath & vaAttachment.Name
' .Remove
End With
'Save the e-mail in order to reflect the deleting of the attached file.
'(A more sophisticated approach may be considered if several e-mails have
'several attachments in order to avoid a repeately saving of one e-mail.)
noDocument.Save True, False
End If
Next vaAttachment
End If
End If
Set noDocument = noNextDocument
Loop

'Release objects from memory.
Set noNextDocument = Nothing
Set noDocument = Nothing
Set noView = Nothing
Set noDatabase = Nothing
Set noSession = Nothing

MsgBox "All the attachments in the Inbox have successfully been saved and removed." _
, vbInformation

End Sub


Feedback number WEBB922LVX created by ~Bill Quetfooski on 11/14/2012

Status: Open
Comments:

VBA code works with Inbox, but not ... (~Bill Quetfoosk... 14.Nov.12)
. . Change it from "($test)" to just "t... (~Ned Nimfanakon... 14.Nov.12)
. . Think I know the problem.. (~Bill Quetfoosk... 14.Nov.12)
. . . . No! You are on the wrong track! (~Ned Nimfanakon... 15.Nov.12)
. . . . . . Removing $ sign and using folder do... (~Bill Quetfoosk... 15.Nov.12)
. . . . . . . . You got rid of the dollar. Now get... (~Ned Nimfanakon... 15.Nov.12)
. . . . . . . . . . Heck Yea!!!! That got it! Thanks!!!... (~Bill Quetfoosk... 15.Nov.12)
. . Did you actually name your view/fol... (~Vanessa Minjum... 14.Nov.12)
. . . . The view exists? (~Jennifer Fezji... 14.Nov.12)




Printer-friendly

Search this forum

Member Tools


RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS